package com.amorcloud.pig.activity;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.amorcloud.pig.MyApp;
import com.amorcloud.pig.R;

public class SettingsActivity extends BaseActivity implements View.OnClickListener {

    TextView serverConfig, userManager;

    @Override
    protected void init() {
        setContentView(R.layout.activity_settings);
        initCustomToolbar(this);
        initView();
        initData();
    }

    private void initView() {
        serverConfig = findViewById(R.id.server_config);
        if(MyApp.isAdmin()) {
            serverConfig.setOnClickListener(this);
        } else {
            serverConfig.setCompoundDrawablesWithIntrinsicBounds(null, getDrawable(R.mipmap.icon_server_settings_disable), null, null);
        }
        userManager = findViewById(R.id.user_manager);
        userManager.setOnClickListener(this);
    }

    private void initData() {

    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            case R.id.server_config:
                intent = new Intent(this, ServerConfigActivity.class);
                intent.putExtra("title", "服务器设置");
                break;
            case R.id.user_manager:
                if(MyApp.isAdmin()) {
                    intent = new Intent(this, UserManagerActivity.class);
                    intent.putExtra("title", "用户管理");
                } else {
                    intent = new Intent(this, ModifyPWDActivity.class);
                    intent.putExtra("title", "密码修改");
                    intent.putExtra("userid", MyApp.currentUser.getId());
                }
                break;
            default:
                break;
        }
        if(intent != null) {
            startActivity(intent);
        }
    }
}
